import React from 'react';
import {
  Chart as ChartJS,
  CategoryScale,
  LinearScale,
  BarElement,
  LineElement,
  ArcElement,
  PointElement,
  Title,
  Tooltip,
  Legend,
  ChartOptions,
} from 'chart.js';
import { Bar, Line, Pie } from 'react-chartjs-2';

// 注册Chart.js组件
ChartJS.register(
  CategoryScale,
  LinearScale,
  BarElement,
  LineElement,
  ArcElement,
  PointElement,
  Title,
  Tooltip,
  Legend
);

export interface ChartProps {
  type: 'bar' | 'line' | 'pie';
  data: any;
  options?: ChartOptions;
  className?: string;
}

const Chart: React.FC<ChartProps> = ({ type, data, options, className }) => {
  switch (type) {
    case 'bar':
      return <Bar data={data} options={options} className={className} />;
    case 'line':
      return <Line data={data} options={options} className={className} />;
    case 'pie':
      return <Pie data={data} options={options} className={className} />;
    default:
      return null;
  }
};

export default Chart;